package com.mccree.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.HttpServerCodec;

public class TestHttpServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        System.out.println("进行初始化方法");
        //向管道中加入处理器
        ChannelPipeline pipeline = ch.pipeline();

        //HttpServerCodec是netty提供的处理http的编解码器
        pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());

        // 数据解码操作
//        pipeline.addLast(new HttpResponseEncoder());
//        // 数据编码操作
//        pipeline.addLast(new HttpRequestDecoder());

        pipeline.addLast("MyTestHttpServerHandler",new TestHttpServerHandler());

        System.out.println("ok...");
    }


}
